package com.simteek.testredis.dao.impl;

import com.google.gson.Gson;
import com.simteek.testredis.dao.BookDao;
import com.simteek.testredis.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BookDaoImpl implements BookDao {

    @Autowired
    protected RedisTemplate redisTemplate;

    @Override
    public List findAll() {
        List list = redisTemplate.boundListOps("book").range(0,-1);
        return list;
    }

    @Override
    public void save(Book book) {
        String jsonObj = new Gson().toJson(book);
        redisTemplate.boundListOps("book").rightPush(jsonObj);
    }

    @Override
    public void delete(String _id) {
//        redisTemplate.boundListOps("book").remove(1,obj);
    }
}
